<template>
	<view class="homeLayout sysBg">
		<CustomNavBar title="推荐"></CustomNavBar>
		<view class="banner">
			<swiper autoplay="true" indicator-dots indicator-color="#007aff" indicator-active-color="#fff">
				<swiper-item v-for="(item,index) in bannerList" :key="index">
					<image :src="item" mode="aspectFill" />
				</swiper-item>
			</swiper>
		</view>
		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="20" color="#28b389"></uni-icons>
				<view class="adv">公告</view>
			</view>
			<view class="center">
				<swiper vertical autoplay interval="1500">
					<swiper-item v-for="item in 4" :key="item">
						滚动的文字滚动的文字滚动的文字滚动的文字滚动的文字滚动的文字滚动的文字滚动的文字滚动的文字滚动的文字滚动的文字
					</swiper-item>
				</swiper>
			</view>
			<view class="right">
				<uni-icons type="right" size="16" color="#333"></uni-icons>
			</view>
		</view>
		<view class="select">
			<view class="recommand">
				<CommonTitle>
					<template #leftSlot>
						<text>每日推荐</text>
					</template>
					<template #rightSlot>
						<uni-icons type="calendar" size="30" color="green"></uni-icons>
						<text>
							<uni-dateformat :date="Date.now()" format="dd日"></uni-dateformat>
						</text>
					</template>
				</CommonTitle>
			</view>
			<view class="content">
				<scroll-view scroll-x>
					<view class="box" v-for="(item,idx) in recommandList" :key="item">
						<image :key="idx" mode="aspectFill" :src="item"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="themeSpecial">
			<view class="title">
				<CommonTitle>
					<template #leftSlot>
						<text>专题精选</text>
					</template>
					<template #rightSlot>
						<navigator url="" class="more">
							<text>More+</text>
						</navigator>
					</template>
				</CommonTitle>
			</view>
			<view class="themeConent">
				<ThemeComponet :themeList="themeList"></ThemeComponet>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import {onLoad,onShow,onShareAppMessage,onShareTimeline} from '@dcloudio/uni-app';
	import { getThemeList } from '@/api/theme/themeApi';
	import { getRecommand } from '@/api/home/homeApi';
	
	
	const recommandList = ref([]);

	const bannerList = ref([
		'https://res.vmallres.com/uomcdn/CN/cms/202503/ada63d50b41043079909b41ffc6ec9a1.jpg',
		'https://res.vmallres.com/uomcdn/CN/cms/202503/ada63d50b41043079909b41ffc6ec9a1.jpg',
		'https://res.vmallres.com/uomcdn/CN/cms/202503/5da58a182a6146f5af3ecb90d3c54c27.png',
		'https://res.vmallres.com/uomcdn/CN/cms/202503/9ae8c1003f1945e69ebb7c44c5f05372.jpg'
	]);

	const themeList = ref([]);
	const getThemeListFromServer = async () => {

		const result : { themeList ?: string[] } = await getThemeList();
		themeList.value = result.themeList;
	}

	const getRecommandList = async () => {
		const res : { recommandList ?: string[] } = await getRecommand();
		recommandList.value = res.recommandList;
	}



	//生命周期函数
	onLoad(async () => {
		getThemeListFromServer();
		getRecommandList();
		
		
		
	});

	onShow(() => {
		console.log('onShow');
	})
	
	
	//分享给好友
	onShareAppMessage((e)=>{
		return {
			title:"华为商城@@",
			path:"/pages/index/index"
		}
	});
	
	
	//分享到朋友圈函数
	onShareTimeline(()=>{
		return {
			title:"华为商城@@",
			imageUrl:"https://res.vmallres.com/portal/1.25.4.300/h5/images/logo_app.png",
			path:"/pages/index/index"
		}
	})
	

	
</script>

<style lang="scss">
	.homeLayout {
		width: 100%;
		padding: 0 30rpx 50rpx;

		.banner {
			//border:1px solid blue;
			//margin: 20rpx auto;
			padding: 20rpx 0;

			swiper {
				width: 100%;
				height: 680rpx;
				border: 10rpx;

				&-item {
					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}
			}
		}

		.notice {
			display: flex;
			justify-content: space-between;
			line-height: 80rpx;
			height: 80rpx;
			//border:1px solid blue;
			overflow: hidden;
			border-radius: 40rpx;

			// background: purple;
			.left {
				width: 120rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.adv {
					color: $my-icon-color;
				}

			}

			.center {
				flex: 1;

				swiper {
					height: 100%;

					&-item {
						height: 100%;
						font-size: 28rpx;
						padding: 0 10rpx;
						color: #666;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}

			.right {
				width: 70rpx;
				text-align: right;
			}
		}

		.select {
			.recommand {
				height: 80rpx;
				line-height: 80rpx;
				// border: 1px solid blue;
				background: #f8f8f8;
			}

			.content {
				width: 100%;
				margin-top: 40rpx;
				background: #e0f7fa;

				scroll-view {
					white-space: nowrap;

					view+view {
						margin-left: 20rpx;
					}

					.box {
						display: inline-block;
						width: 200rpx;
						height: 430rpx;
						image {
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}

					}
				}
			}
		}

		.themeSpecial {

			// border:1px solid blue;
			.title {
				line-height: 80rpx;
				height: 80rpx;

				.more {
					font-size: 32rpx;
					color: #888;
				}
			}
		}
	}
</style>